package ua.keeper.query;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class ClientListActivity extends ListActivity
{
	private int dayOfWeek_ = 0;
	private ClientList list_;
	private ClientListAdapter adapter_;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    	super.onCreate(savedInstanceState);
    	
    	dayOfWeek_ = Integer.parseInt(getIntent().getExtras().getString("dayOfWeek"));
    	
    	QueryApp appState = ((QueryApp)getApplicationContext());
    	list_ = new ClientList(appState.getDataBase(), dayOfWeek_);
    	
    	adapter_ = new ClientListAdapter(this, R.layout.clients_list_row, list_.list);
        
        setListAdapter(adapter_);
    }
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
    	int clientId = adapter_.getItem(position).getId();
    	if (clientId >= 0)
    	{
    		Intent myIntent = new Intent(ClientListActivity.this, DocHListActivity.class);
        	myIntent.putExtra("clientId", Integer.toString(clientId));
        	ClientListActivity.this.startActivity(myIntent);
    	}
    	else
    	{
    		Toast.makeText(this, "<Error>", Toast.LENGTH_SHORT).show();
    	}
    }
}
